<template>
  <el-dialog
    :title="!dataForm.pkId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="办件所属事项编号" prop="catalogcode">
      <el-input v-model="dataForm.catalogcode" placeholder="办件所属事项编号"></el-input>
    </el-form-item>
    <el-form-item label="办件事项编号" prop="projectno">
      <el-input v-model="dataForm.projectno" placeholder="办件事项编号"></el-input>
    </el-form-item>
    <el-form-item label="办理业务环节编号" prop="rowguid">
      <el-input v-model="dataForm.rowguid" placeholder="办理业务环节编号"></el-input>
    </el-form-item>
    <el-form-item label="办理环节名称" prop="processName">
      <el-input v-model="dataForm.processName" placeholder="办理环节名称"></el-input>
    </el-form-item>
    <el-form-item label="办理机构" prop="processOrgname">
      <el-input v-model="dataForm.processOrgname" placeholder="办理机构"></el-input>
    </el-form-item>
    <el-form-item label="办件所在区域" prop="administrativepDiv">
      <el-input v-model="dataForm.administrativepDiv" placeholder="办件所在区域"></el-input>
    </el-form-item>
    <el-form-item label="办理人ID" prop="handleuserId">
      <el-input v-model="dataForm.handleuserId" placeholder="办理人ID"></el-input>
    </el-form-item>
    <el-form-item label="办理人姓名" prop="handleusername">
      <el-input v-model="dataForm.handleusername" placeholder="办理人姓名"></el-input>
    </el-form-item>
    <el-form-item label="办理意见" prop="handleexplain">
      <el-input v-model="dataForm.handleexplain" placeholder="办理意见"></el-input>
    </el-form-item>
    <el-form-item label="环节结束时间" prop="eventendtime">
      <el-input v-model="dataForm.eventendtime" placeholder="环节结束时间"></el-input>
    </el-form-item>
    <el-form-item label="交换标志" prop="changeFlag">
      <el-input v-model="dataForm.changeFlag" placeholder="交换标志"></el-input>
    </el-form-item>
    <el-form-item label="入库时间" prop="synTime">
      <el-input v-model="dataForm.synTime" placeholder="入库时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          pkId: 0,
          catalogcode: '',
          projectno: '',
          rowguid: '',
          processName: '',
          processOrgname: '',
          administrativepDiv: '',
          handleuserId: '',
          handleusername: '',
          handleexplain: '',
          eventendtime: '',
          changeFlag: '',
          synTime: ''
        },
        dataRule: {
          catalogcode: [
            { required: true, message: '办件所属事项编号不能为空', trigger: 'blur' }
          ],
          projectno: [
            { required: true, message: '办件事项编号不能为空', trigger: 'blur' }
          ],
          rowguid: [
            { required: true, message: '办理业务环节编号不能为空', trigger: 'blur' }
          ],
          processName: [
            { required: true, message: '办理环节名称不能为空', trigger: 'blur' }
          ],
          processOrgname: [
            { required: true, message: '办理机构不能为空', trigger: 'blur' }
          ],
          administrativepDiv: [
            { required: true, message: '办件所在区域不能为空', trigger: 'blur' }
          ],
          handleuserId: [
            { required: true, message: '办理人ID不能为空', trigger: 'blur' }
          ],
          handleusername: [
            { required: true, message: '办理人姓名不能为空', trigger: 'blur' }
          ],
          handleexplain: [
            { required: true, message: '办理意见不能为空', trigger: 'blur' }
          ],
          eventendtime: [
            { required: true, message: '环节结束时间不能为空', trigger: 'blur' }
          ],
          changeFlag: [
            { required: true, message: '交换标志不能为空', trigger: 'blur' }
          ],
          synTime: [
            { required: true, message: '入库时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.pkId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.pkId) {
            this.$http({
              url: this.$http.adornUrl(`/wsbj/upproprocess/info/${this.dataForm.pkId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.catalogcode = data.upProProcess.catalogcode
                this.dataForm.projectno = data.upProProcess.projectno
                this.dataForm.rowguid = data.upProProcess.rowguid
                this.dataForm.processName = data.upProProcess.processName
                this.dataForm.processOrgname = data.upProProcess.processOrgname
                this.dataForm.administrativepDiv = data.upProProcess.administrativepDiv
                this.dataForm.handleuserId = data.upProProcess.handleuserId
                this.dataForm.handleusername = data.upProProcess.handleusername
                this.dataForm.handleexplain = data.upProProcess.handleexplain
                this.dataForm.eventendtime = data.upProProcess.eventendtime
                this.dataForm.changeFlag = data.upProProcess.changeFlag
                this.dataForm.synTime = data.upProProcess.synTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/wsbj/upproprocess/${!this.dataForm.pkId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'pkId': this.dataForm.pkId || undefined,
                'catalogcode': this.dataForm.catalogcode,
                'projectno': this.dataForm.projectno,
                'rowguid': this.dataForm.rowguid,
                'processName': this.dataForm.processName,
                'processOrgname': this.dataForm.processOrgname,
                'administrativepDiv': this.dataForm.administrativepDiv,
                'handleuserId': this.dataForm.handleuserId,
                'handleusername': this.dataForm.handleusername,
                'handleexplain': this.dataForm.handleexplain,
                'eventendtime': this.dataForm.eventendtime,
                'changeFlag': this.dataForm.changeFlag,
                'synTime': this.dataForm.synTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
